import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Breadcrumb } from 'antd';

import AccountSetting from '../AccountSetting/AccountSetting';
import SetPassword from '../SetPassword/SetPassword';

import './AccountInfo.scss';

const classNames = require('classnames');

class AccountInfo extends Component {
  state = {
    visible: false,
    passwordEditVisible: false,
  }
  componentWillReceiveProps (nextProps) {
    this.setState({
      visible: nextProps.visible,
    });
  }
  togglePasswordEdit = () => {
    const { passwordEditVisible } = this.state;
    this.setState({
      passwordEditVisible: !passwordEditVisible,
    });
  }
  render () {
    const className = classNames('account-view page', { hide: !this.state.visible });
    return (
      <div className={className}>
        <header>
          <Breadcrumb>
            <Breadcrumb.Item>首页</Breadcrumb.Item>
            <Breadcrumb.Item>个人资料</Breadcrumb.Item>
          </Breadcrumb>
          <div className="page-title">个人资料</div>
        </header>
        {
          this.state.passwordEditVisible ?
            <SetPassword togglePasswordEdit={this.togglePasswordEdit} /> :
            <AccountSetting togglePasswordEdit={this.togglePasswordEdit} />
        }
      </div>
    );
  }
}

AccountInfo.propTypes = {
  visible: PropTypes.bool.isRequired,
};

export default AccountInfo;
